package com.matrix.index.ui.setting

import android.os.Environment
import androidx.activity.enableEdgeToEdge
import androidx.lifecycle.lifecycleScope
import com.alibaba.android.arouter.facade.annotation.Route
import com.blankj.utilcode.util.FileUtils
import com.blankj.utilcode.util.ToastUtils
import com.matrix.basecore.arouter.ARouterUtils
import com.matrix.basecore.base.BaseActivity
import com.matrix.basecore.constant.Constant
import com.matrix.index.databinding.ActivitySettingBinding
import kotlinx.coroutines.launch
import java.io.File

@Route(path = Constant.ARouterPath.SettingActivityPath)
class SettingActivity : BaseActivity<ActivitySettingBinding>() {

    override fun getViewBinding(): ActivitySettingBinding {
        enableEdgeToEdge()
        return ActivitySettingBinding.inflate(layoutInflater)
    }

    override fun initView() {

    }

    override fun initListener() {
        mViewBinding.ivBack.setOnClickListener {
            finish()
        }

        mViewBinding.rlAgree.setOnClickListener {
            ARouterUtils.startSettingAboutUs(Constant.ASSETSPATH + "agreement.html", "用户协议")
        }

        mViewBinding.rlSecret.setOnClickListener {
            ARouterUtils.startSettingAboutUs(Constant.ASSETSPATH + "secret.html", "隐私政策")
        }

        mViewBinding.rlResp.setOnClickListener {
            ARouterUtils.startSettingAboutUs(
                Constant.ASSETSPATH + "responsibility.html",
                "免责申明"
            )
        }

        mViewBinding.rlWallpaper.setOnClickListener {
            ARouterUtils.startAnimWallpaperActivity()
        }

        mViewBinding.rlSkill.setOnClickListener {
            ARouterUtils.startSettingAboutUs("https://www.lanzout.com/", "技术介绍")
        }

        mViewBinding.rlCache.setOnClickListener {
            val sdCardDir = File(
                Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).path,
                Constant.CachePath
            )
            lifecycleScope.launch {
                FileUtils.delete(sdCardDir)
            }
            ToastUtils.showShort("清楚缓存成功")
        }

        mViewBinding.rlUpdate.setOnClickListener {

        }
    }
}